package com.moon.robot.Controller;

import com.alibaba.fastjson.JSON;
import com.forte.qqrobot.BotRuntime;
import com.forte.qqrobot.beans.messages.result.GroupList;
import com.forte.qqrobot.bot.BotInfo;
import com.forte.qqrobot.bot.BotManager;
import com.forte.qqrobot.bot.BotSender;
import com.moon.robot.RobotApplication;
import com.moon.robot.pojo.Group;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Response;
import java.util.ArrayList;
import java.util.List;

@Controller
public class PageController {


    @RequestMapping("/index")
    public String index(Model model) {
        return "index";
    }

    @RequestMapping("/test")
    public String test(HttpServletResponse response, Model model) {
        BotRuntime runtime = BotRuntime.getRuntime();
        BotManager botManager = runtime.getBotManager();
        BotInfo botInfo = botManager.defaultBot();
        BotSender sender = botInfo.getSender();
        GroupList groupList = sender.GETTER.getGroupList();


        List<Group> groupslis = new ArrayList<>();
        groupList.forEach(groups -> {
            Group group = new Group(groups.getGroupCode(), groups.getHeadUrl(), groups.getName());
            groupslis.add(group);
        });
        model.addAttribute("grouplist", groupslis);
        String string = JSON.toJSONString(RobotApplication.lastnews);
        model.addAttribute("msglist", string);
        return "test";
    }
}
